<%@page import="com.bean.User"%>
<%@page import="com.dao.UserDao"%>
<%@ page import="com.util.QQUtils" %>
<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
         
 <%
 
 String username = request.getParameter("username");
 String password = request.getParameter("password");
 String password2 = request.getParameter("password2");
 String sex = request.getParameter("sex");
 String age = request.getParameter("age");
 String qq = request.getParameter("qq");
 String m = request.getParameter("m");
 UserDao dao = new UserDao();
 
 User obj = new User();
 if("login".equals(m)){
	obj= dao.findOne(qq);
	if(obj.getPassword()!=null && password.equals(obj.getPassword())){
		session.setAttribute("user", obj);
		response.sendRedirect("index.jsp");
	}else{
		 request.setAttribute("message", "QQ或密码不正确");
		 request.getRequestDispatcher("login.jsp").forward(request, response);
	}
	
	 
 }else{
	 
	 obj.setUsername(username);
	 obj.setPassword(password);
	 obj.setSex(sex);
	 obj.setAge(age);
	 obj.setQq(qq);
	 obj.setHeadPic(QQUtils.genQQHeader());
	User validateObj= dao.findOne(obj.getQq());
	 if(validateObj==null || validateObj.getId()<1){
		 
		 dao.saveUser(obj);
		 request.setAttribute("message", "注册成功");
		 request.getRequestDispatcher("login.jsp").forward(request, response);
	 }else{
		 
		 request.setAttribute("message", "用户已经存在不能注册");
		 request.getRequestDispatcher("register.jsp").forward(request, response);
	 } 
	 
 }
   
 %>
 
 
